package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.entity.Cart;
import com.situ.mall.entity.Result;
import com.situ.mall.entity.Suggest;
import com.situ.mall.entity.User;
import com.situ.mall.mapper.CartMapper;
import com.situ.mall.mapper.SuggestMapper;
import com.situ.mall.service.ICartService;
import com.situ.mall.service.ISuggestService;

@Service
public class SuggestServiceImpl implements ISuggestService{
	@Autowired
	private CartMapper cartMapper;
	@Autowired
	private SuggestMapper suggestMapper;

	@Override
	public Result selectByPage(Integer page, Integer limit) {
		System.out.println("SuggestServiceImpl.selectByPage()");
		// 查询一种有多少条数据
		int count = suggestMapper.getTotalCount();
		// 当前页数据
		int offset = (page -1 ) * limit;
		List<Suggest> list = suggestMapper.selectByPage(offset, limit);
		for (Suggest suggest : list) {
			System.out.println(suggest);
		}
		return Result.success("", list, count);
	}

	@Override
	public boolean deleteById(Integer id) {
		int count = suggestMapper.deleteByPrimaryKey(id);
		return count == 1 ? true : false;
	}

	@Override
	public Suggest getReplyUserInfo(Integer id) {
		Suggest suggest = suggestMapper.selectByPrimaryKey(id);
		return suggest;
	}

	@Override
	public boolean replyNow(Suggest suggest) {
		int count = suggestMapper.replyNow(suggest);
		return count == 1 ? true : false;
	}

	@Override
	public List<Suggest> selectSuggestByUserId(Integer userId) {
		List<Suggest> list = suggestMapper.selectSuggestByUserId(userId);
		return list;
	}
	
}